<?php
/**
 * Description:  门店留资
 * Created by PhpStorm.
 * User: 玉坤
 * Date: 2021/9/9
 * Time: 14:04
 */


ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
ini_set('memory_limit', '1024M');

require_once '/data/wwwroot/g_vendor/autoload.php';


$start = microtime(true);
$page = 1;
$pageSize = 1000;
$lists = [];
$all_num = [];
$err = [];

do {
    $limit = [($page - 1) * $pageSize, $pageSize];
    $where = [
        "LIMIT" => $limit,
        "city_id[!]" => '',
    ];
    $lists = \Biz\model\store\StoreUserConsult::getListByWhere($where, ["id", "city_id"]);

    $data = [];

    foreach ($lists as $list) {
        try {
            $codes = explode(",", $list['city_id']);
            if ($codes) {
                $code = array_pop($codes);
                $code = \Hhz\AdministrativeRegion\Region::getCodeByOldCode($code);
                if (!$code){
                    continue;
                }
                $update['area_code'] = $code;
                $update['area_name'] = \Hhz\AdministrativeRegion\Region::getAreaDetailByCode($code);
                if ($update) {
                    $ret = \Biz\model\store\StoreUserConsult::update($update, ['id' => $list['id']]);
                    if ($ret->errorCode() !== '00000') {
                        $err[] = $list['id'];
                    } else {
                        $all_num[] = $list['id'];
                    }

                }
            }

        } catch (\Exception $e) {
            print $e->getMessage();
            exit();
        }
    }
    $page++;
} while ($lists);

$successNum = count($all_num);
$errNum = count($err);
$end = microtime(true);
$time = $end - $start;
$second = round($time, 3);
var_dump('完成时间：' . date('Y-m-d H:i:s') . '   总耗时:' . $second . '秒' . "  成功数量" . $successNum . "  失败数量" . $errNum);

